package base

import "net/http"

// Response 基础序列化器
type Response struct {
	Success bool        `json:"success"`
	Data    interface{} `json:"data"`
	Msg     string      `json:"msg"`
	Code    int         `json:"code"`
}

func SuccessResponse(data interface{}) *Response {
	return &Response{
		Success: true,
		Data:    data,
		Code:    http.StatusOK,
	}
}

func FailedResponse(code int, err string) *Response {
	return &Response{
		Success: false,
		Msg:     err,
		Code:    code,
	}
}

func FailedResponseWithoutCode(err string) *Response {
	return &Response{
		Success: false,
		Msg:     err,
		Code:    http.StatusInternalServerError,
	}
}
